package com.carpark.ejb.Model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Krzysztof
 */
@Entity
@Table(name = "parkingspaces")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ParkingspacesModel.findAll", query = "SELECT p FROM ParkingspacesModel p"),
    @NamedQuery(name = "ParkingspacesModel.findByNumber", query = "SELECT p FROM ParkingspacesModel p WHERE p.number = :number"),
    @NamedQuery(name = "ParkingspacesModel.findByType", query = "SELECT p FROM ParkingspacesModel p WHERE p.type = :type"),
    @NamedQuery(name = "ParkingspacesModel.findByTypeStatus", query = "SELECT p FROM ParkingspacesModel p WHERE p.type = :type AND p.status <> :status"),
    @NamedQuery(name = "ParkingspacesModel.findByTimeAnType", query = "SELECT k FROM ParkingspacesModel k INNER JOIN k.parkingpassesModelCollection s WHERE( s.dateIssue < :dateExp AND :dateExp <s.expirationDate) OR( s.dateIssue > :dateIs AND :dateExp > s.expirationDate) OR (s.dateIssue < :dateIs AND :dateIs <s.expirationDate) OR (s.passType = :passType)"),
    @NamedQuery(name = "ParkingspacesModel.findByStatus", query = "SELECT p FROM ParkingspacesModel p WHERE p.status = :status")})
public class ParkingspacesModel implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "Number")
    private Integer number;
    @Size(max = 10)
    @Column(name = "Type")
    private String type;
    @Size(max = 8)
    @Column(name = "Status")
    private String status;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "numberId")
    private Collection<ParkingpassesModel> parkingpassesModelCollection;

    public ParkingspacesModel() {
    }

    public ParkingspacesModel(Integer number) {
        this.number = number;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (number != null ? number.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ParkingspacesModel)) {
            return false;
        }
        ParkingspacesModel other = (ParkingspacesModel) object;
        if ((this.number == null && other.number != null) || (this.number != null && !this.number.equals(other.number))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return number.toString();
    }

}
